﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JuCloudy.Draw
{
    public class Sector : Shape
    {
        /// <summary>
        /// 扇形的半径大小，更改其值会影响扇形大小。
        /// </summary>
        private const int Radius = 10;

        public static Path GetBaseStation(double rotationAngle)
        {
            var path = new Path
            {
                Fill = new SolidColorBrush(Colors.Green),
                //以扇形的两直线连接顶点为几何中心进行定位和旋转。
                RenderTransformOrigin = new Point(0.5, 1),
                Stretch = Stretch.None,
                UseLayoutRounding = false
            };
            //以几何中心为准直线顶点的偏移值。
            var offsetx = Radius * Math.Cos(20);
            var offsety = Radius * Math.Sin(20);

            //绘制起始直线
            var startLine = new LineSegment()
            {
                Point = new Point(0 - offsetx, 0 - offsety)
            };
            //绘制弧线,一条三次方贝塞尔曲线,Point1起点，Point2为峰值点，Point3为终点。
            var arcLine = new BezierSegment()
            {
                Point1 = new Point(0 - offsetx, 0 - offsety),
                Point2 = new Point(0, 0 - Radius),
                Point3 = new Point(0 + offsetx, 0 - offsety)
            };
            //绘制结束直线
            var endLine = new LineSegment()
            {
                Point = new Point(0, 0)
            };
            //把三条线段集合在一起。
            var segments = new PathSegmentCollection { startLine, arcLine, endLine };

            //为直线的Data赋值，由三段封闭的线段绘制成一个扇形
            path.Data = new PathGeometry()
            {
                Figures = new PathFigureCollection() { new PathFigure()
                                                           {
                                                               StartPoint = new Point(0, 0),
                                                               Segments = segments
                                                           }}
            };

            //设置扇形对称轴偏转角度。
            path.RenderTransform = new CompositeTransform() { Rotation = rotationAngle };

            return path;
        }
    }
}
